package org.vectrics.common.db;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.vectrics.user.Person;

public class ObjectNote implements RecordObject {
	public static int PAGE_MAX_CHARACTERS = 200;
	
	private Long id = null;
	private List objectNotePages = new ArrayList();
	private Date dateCreated = new Date();
	private Person author = null;
	private String objectType = null;
	private String objectKey = null;

	
	public ObjectNote() {
		super();
	}


	public Long getId() {
		return id;
	}


	public void setId(Long id) {
		this.id = id;
	}


	public List getObjectNotePages() {
		return objectNotePages;
	}


	public void setObjectNotePages(List objectNotePages) {
		this.objectNotePages = objectNotePages;
	}


	public Person getAuthor() {
		return author;
	}


	public void setAuthor(Person author) {
		this.author = author;
	}


	public Date getDateCreated() {
		return dateCreated;
	}


	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}


	public String getObjectKey() {
		return objectKey;
	}


	public void setObjectKey(String objectKey) {
		this.objectKey = objectKey;
	}


	public String getObjectType() {
		return objectType;
	}


	public void setObjectType(String objectType) {
		this.objectType = objectType;
	}


	public void setText(String text) {
		String remainingText = text;
		this.getObjectNotePages().clear();
		int c = 0;
		int pageNumber = 0;
		boolean done = false;
		while (done == false) {
			String currentPageText = remainingText.substring(c, c + PAGE_MAX_CHARACTERS);
			remainingText = text.substring(PAGE_MAX_CHARACTERS);
			ObjectNotePage page = new ObjectNotePage();
			page.setObjectNote(this);
			page.setPageNumber(pageNumber);
			c += PAGE_MAX_CHARACTERS;
			if (c > text.length()) {
				done = true;
			}
			pageNumber++;
		}
	}
	
}
